home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / bin / zcrypt.z / zcrypt
Encoding:
Text File  |  1997-01-22  |  1.4 KB  |  69 lines

  1. : zcrypt
  2. # Copyright 1993-94 Z-Code Software, a Division of NCD.  All rights reserved.
  3. if test -z "$TMPDIR"
  4. then
  5.     TMPDIR=/tmp
  6. fi
  7. TMPF=$TMPDIR/ocr$$
  8. if test -z "$CRYPT"
  9. then
  10.     CRYPT=crypt
  11. fi
  12.  
  13. # Some crypts use "CrYpTkEy", for whatever weird reason.
  14. if test -n "$CRYPTKEY"; then CrYpTkEy="$CRYPTKEY"; fi
  15. if test -n "$CrYpTkEy"; then CRYPTKEY="$CrYpTkEy"; fi
  16. export CRYPTKEY
  17. export CrYpTkEy
  18.  
  19. case $1 in
  20. -e) ICONV=cat; OCONV=btoa; shift;;
  21. -u) ICONV=atob; OCONV=cat; CRYPTKEY=""; shift;;
  22. *)
  23.     if grep "xbtoa Begin" "$1" >/dev/null 2>/dev/null
  24.     then
  25.     ICONV=atob; OCONV=cat; CRYPTKEY=""
  26.     else
  27.     ICONV=cat; OCONV=btoa
  28.     fi
  29.     ;;
  30. esac
  31. case $CRYPT in
  32. *crypt) if test -n "$CRYPTKEY"; then CRYPT="$CRYPT -k"; fi;;
  33. esac
  34. if test $# -eq 0
  35. then
  36.     set $TMPDIR/icr$$
  37.     cat > $1
  38. fi
  39. if test -z "$DISPLAY"
  40. then
  41.     # This is a hack because we can't prompt if no $DISPLAY
  42.     case $CRYPT in
  43.     crypt*|crypt*-k*)
  44.     if test -n "$CRYPTKEY"
  45.     then
  46.         echo "Can't get key from environment; can't encrypt" 1>&2
  47.         exit 1
  48.     fi
  49.     ;;
  50.     esac
  51.     CRYPT="($CRYPT 2>/dev/null || eval 'echo $CRYPT failed 1>&2 ; exit 1')"
  52.     $ICONV < "$1" | eval "$CRYPT" > $TMPF
  53. else
  54.     if test -z "$CRYPTKEY"
  55.     then
  56.     xterm -geometry 40x5+200+200 -e sh -c "$ICONV < '$1' | $CRYPT > $TMPF"
  57.     else
  58.     $ICONV < "$1" | eval "$CRYPT" > $TMPF
  59.     fi
  60. fi
  61. if test -s $TMPF
  62. then
  63.     $OCONV < $TMPF
  64. else
  65.     echo "$CRYPT failed" 1>&2
  66.     exit 1
  67. fi
  68. rm $TMPDIR/*$$
  69.